
import java.io.IOException;
import java.io.OutputStream;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author David
 */
public class Response {
    private Request request;
    private ServerConfig config;

    public Response(){
        request = new Request();
    }

    public Response(ServerConfig config){
        this.config = config;
    }

    public void processRequest(Request request){
        this.request = request;
    }

    public void writeOutput(OutputStream serverOutput){
        if(this.request.getCommand().equals("availability")){
            try {
                String response = "200 OK";
                serverOutput.write(response.getBytes(), 0, response.length()-1);
                System.out.println(response+"\r\n\r\n");
            } catch (IOException ex) {
                System.out.println("Error writing to server");
            }
        }else if(this.request.getCommand().equals("system-status")){
            try {
                CommandHandler command = new CommandHandler(config);
                String response = command.execCommand("system-status");
                serverOutput.write(response.getBytes(), 0, response.length()-1);
                System.out.println(response+"\r\n\r\n");
            } catch (IOException ex) {
                System.out.println("Error writing to server");
            }
        }else if(this.request.getCommand().equals("create-job")){

        }
    }
}
